package com.liu.yupao.once;

import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author lqh
 * @since 2025-09-05 13:55
 * 导入用户信息到数据库
 */
public class ImportExcelUserInfo {
    public static void main(String[] args) {
        String fileName ="E:\\dev\\YuPao\\yupao-backend\\src\\main\\resources\\Test.xlsx";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 同步读取会自动finish
        List<UserInfo> list = EasyExcel.read(fileName).head(UserInfo.class).sheet().doReadSync();
        for (UserInfo data : list) {
            System.out.println ("读取数据:"+data);
        }
        //总条数
        System.out.println ("总数:"+list.size ());
        //用户数(去重)
        Map<String, List<UserInfo>> listMap =
                list.stream ()
                        .filter (item->StrUtil.isNotEmpty (item.getUserName ()))
                        .collect (Collectors.groupingBy (UserInfo::getUserName));
        for (Map.Entry<String, List<UserInfo>> listEntry : listMap.entrySet ()) {
            //用户名分组查询
            if (listEntry.getValue ().size ()>1){
                System.out.println ("UserName=>"+listEntry.getKey ());
            }
        }


    }
}
